package com.foxzzz.two.pointers;

public class Solution11 {

    //暴力法
    public int maxArea1(int[] height) {

        int max = 0;
        for (int i = 0; i < height.length; i++) {
            for (int j = i + 1; j < height.length; j++) {
                max = Math.max(max, (j - i) * Math.min(height[i], height[j]));
            }
        }
        return max;
    }

    //首尾双指针
    public int maxArea(int[] height) {
        if (height.length == 0) {
            return 0;
        }
        int l = 0, h = height.length - 1, area = 0;
        while (l < h) {
            area = Math.max(area, (h - l) * Math.min(height[l], height[h]));
            if (height[l] < height[h]) {

                l++;
            } else {
                h--;

            }

        }

        return area;
    }


    public static void main(String[] args) {
        System.out.println(new Solution11().maxArea(new int[]{1, 8, 6, 2, 5, 4, 8, 3, 7}));
    }
}
